namespace Plugins.Engine.Internal
{
    using System;
    using System.Diagnostics.CodeAnalysis;
    using System.IO;
    using System.Reflection;
    using Plugins.Library;

    [Serializable]
    internal class PluginTypeContainer : IPluginTypeContainerInternal
    {
        public T Create<T>(Assembly assembly)
        {
            return (T) assembly.CreateInstance(typeof(T).FullName);
        }

        [SuppressMessage("Microsoft.Design", "CA1031")]
        public Assembly LoadAssembly(string assemblyFile)
        {
            try
            {
                if (File.Exists(assemblyFile))
                {
                    byte[] data = File.ReadAllBytes(assemblyFile);
                    return Assembly.Load(data);
                }
            }
            catch (Exception ex)
            {
                PluginLog.WriteErrorSync(ex);
            }
            return null;
        }
    }
}

